// pages/home/home.js
var app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    config: {
      searchShow: false
    },
    userInfo: {
      nickName: '',  //用户昵称
      avatarUrl: '../../resources/user.png', //用户头像
      power: 0  //用户权限
    },
    img: {
      path: '../../resources/',
      src: '../../resources/user.png',
      activity: '../../resources/activity_2.png',
      activity_trip: '../../resources/activity_trip_1.png',
      activity_msg: '../../resources/activity_1.png',
      activity_tongji: '../../resources/activity_tongji.png',
      gift: '../../resources/gift.png',
      summary: '../../resources/summary.png',
      summary_2: '../../resources/summary_2.png',
      manage: '../../resources/activity_1.png',
      list: '../../resources/list.png',
      student: '../../resources/student_1.png',
      student_2: '../../resources/student_2.png',
      teacher: '../../resources/teacher_1.png',
      teacher_2: '../../resources/teacher_2.png',
      course: '../../resources/course_1.png',
      course_2: '../../resources/course_2.png',
      hours: '../../resources/hours_1.png',
      work_1: '../../resources/work_1.png',
      work_1_1: '../../resources/work_1_1.png',
      work_2: '../../resources/work_2.png',
      work_2_1: '../../resources/work_2_1.png',
      work_3_1: '../../resources/work_3_1.png',
      wages: '../../resources/wages.png',
      leave: '../../resources/leave.png',
      class_1: '../../resources/class_1.png',
      topic: '../../resources/topic.png',
      recommend: '../../resources/recommend.png',
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // console.log(app.login)
    // console.log(app.userInfo.nickName, app.userInfo.avatarUrl)
    // console.log('exp1: ',app.exp)
    // console.log('exp2: ',app.util.time())
    // app.util.expire(app.exp)
    this.setData({
      userInfo: {
        nickName: app.userInfo.nickName,
        avatarUrl: app.userInfo.avatarUrl,
        power: app.power
      },
      login: app.login
    })
    console.log('reset: ', this.data.userInfo)

    app.util.getSchoolInfo({ t: app.login.t }, function (res) {
      app.school = res.data.data
    })
    app.util.getGradeInfo({ t: app.login.t }, function (res) {
      app.grade = res.data.data
    })
  },

  userInfo: function (event) {
    console.log(event);
    wx.navigateTo({
      url: '../user/info',
    });
  },
  addStudent: function (event) {
    console.log(event);
    wx.navigateTo({
      url: '../student/add',
    });
  },
  addTeacher: function (event) {
    console.log(event);
    wx.navigateTo({
      url: '../teacher/add',
    });
  },
  addClass: function (event) {
    console.log(event);
    wx.navigateTo({
      url: '../class/add',
    });
  },
  userInfo: function (event) {
    console.log(event);
    wx.navigateTo({
      url: '../user/info',
    });
  },
  addCourse: function (event) {
    wx.navigateTo({
      url: '../course/add',
    });
  },

  inputSearch: function (event) {
    console.log(event.detail);
    if (event.detail.value !== '') {
      this.setData({
        config: {
          searchShow: true
        }
      })
    } else {
      this.setData({
        config: {
          searchShow: false
        }
      })
    }
  },

  startSearch: function (event) {
    //这里触发搜索过程
  },

  inputStudentInfo: function (e) {
    var type = e.currentTarget.dataset.type
    app.util.goTo('../kecheng/teach?c=' + app.login.z)
    // if (type === 'zuowen') {
    //   app.util.goTo('../kecheng/zuowen/teach')
    // } else if (type === 'aoshu') {
    //   app.util.goTo('../kecheng/aoshu/teach')
    // } else if (type === 'shufa') {
    //   app.util.goTo('../kecheng/shufa/teach')
    // }
  },

  inputOutLine: function (e) {
    var type = e.currentTarget.dataset.type
    app.util.goTo('../kecheng/outline?c=' + app.login.z)
    // if (type === 'zuowen') {
    //   app.util.goTo('../kecheng/zuowen/outline')
    // } else if (type === 'aoshu') {
    //   app.util.goTo('../kecheng/aoshu/outline')
    // } else if (type === 'shufa') {
    //   app.util.goTo('../kecheng/shufa/outline')
    // }
  },

  inputTaskInfo: function (e) {
    var type = e.currentTarget.dataset.type
    app.util.goTo('../kecheng/show?c=' + app.login.z)
    // if (type === 'zuowen') {
    //   app.util.goTo('../kecheng/zuowen/show')
    // } else if (type === 'aoshu') {
    //   app.util.goTo('../kecheng/aoshu/show')
    // } else if (type === 'shufa') {
    //   app.util.goTo('../kecheng/shufa/show')
    // }
  },

  selectFun: function (e) {
    var type = e.currentTarget.dataset.type
    if (type === 'Student') {
      app.util.goTo('../student/list')
    }
    if (type === 'Teacher') {
      app.util.goTo('../teacher/list')
    }
    if (type === 'Course') {
      app.util.goTo('../course/list')
    }
    if (type === 'Hours') {
      app.util.goTo('../course/hours')
    }
  },

  classInfo: function (e) {
    var type = e.currentTarget.dataset.type
    app.util.goTo('../kecheng/class?c=' + app.login.z)
    // if (type === 'zuowen') {
    //   app.util.goTo('../kecheng/zuowen/class')
    // } else if (type === 'aoshu') {
    //   app.util.goTo('../kecheng/aoshu/class')
    // } else if (type === 'shufa') {
    //   app.util.goTo('../kecheng/shufa/class')
    // }
  },

  checkin: function (e) {
    var type = e.currentTarget.dataset.type
    if (type === 'my') {
      app.util.goTo('../center/checkin')
    } else if (type === 'calendar') {
      app.util.goTo('../calendar/dateSelect')
    }
  },

  activeBindtap: function (e) {
    var sType = e.currentTarget.dataset.type
    if (sType == 'create') {//创建活动
      app.app.util.goTo('../active/create')
    } else if (sType == 'list') {//活动列表
      app.app.util.goTo('../active/index')
    } else if (sType == 'total') {//活动统计
      app.app.util.goTo('../active/total')
    } else if (sType == 'manage') {//活动管理
      app.app.util.goTo('../active/manage')
    } else if (sType == 'msg') {//客服消息
      app.app.util.goTo('../center/message')
    }
  }
})